<?php

/**
 * Created by PhpStorm.
 * User: evan
 * Date: 2017/9/4
 * Time: 下午5:25
 */
class Base extends MY_Callback_Controller
{
    public function index()
    {
        $content = file_get_contents("php://input");




        echo $response = '{"ActionStatus": "OK","ErrorInfo": "","ErrorCode": 0}';//p(json_decode($response, true));
        record_log($content);
        /*$content = '
        {
            "CallbackCommand": "Group.CallbackAfterSendMsg",
            "From_Account": "523901",
            "GroupId": "@TGS#aYH6H75E6",
            "MsgBody": [
                {
                    "MsgContent": {
                        "Text": "@MSMK@TYPE_PRIVACY_VOICE_CONNECT@aa668888866aa1"
                    },
                    "MsgType": "TIMTextElem"
                }s
            ],
            "MsgSeq": 10,
            "MsgTime": 1508899820,
            "Type": "AVChatRoom"
        }
        ';
        //*/


        if (empty($content))
        {
            return;
        }


        $item = json_decode($content, true);
        if (empty($item))
        {
            return;
        }


        $message = $item['MsgBody'][0]['MsgContent']['Text'];
        if (false !== strpos($message, 'MSMK@TYPE_PRIVACY_VOICE_CONNECT@aa668888866aa'))
        {
            $this->enable_mixed_flow($item['From_Account'], $message);
            return ;
            //record_log($content);
        }



        if (false !== strpos($message, 'MSMK@LIVE_ROOM_STAUTS@'))
        {
            $this->cancel_mixed_flow($item['From_Account']);
            return ;
        }
    }


    public function enable_mixed_flow($auction_uid, $message)
    {
        $is_radio = str_replace('@MSMK@TYPE_PRIVACY_VOICE_CONNECT@aa668888866aa', '', $message);


        $where = array
        (
            'auction_uid' => $auction_uid,
            'is_public'   => DIRECT_SEEDING_IS_PUBLISH_CLOSE,
            'status'      => DS_STATUS_DOING,
        );
        $this->load->model('direct_seeding/Model_direct_seeding', 'ds');
        $ds_item = $this->ds->getOne($where);
        if (empty($ds_item))
        {
            return ;
        }



        sleep(2);
        $this->load->service('direct_seeding/service_direct_seeding_mixed_flow');
        $data = $this->service_direct_seeding_mixed_flow->index($ds_item['ds_id'], DIRECT_SEEDING_MIXED_FLOW_TYPE_ENABLE, $is_radio);
    }


    public function cancel_mixed_flow($auction_uid)
    {
        $where = array
        (
            'auction_uid' => $auction_uid,
            'is_public'   => DIRECT_SEEDING_IS_PUBLISH_CLOSE,
            'status'      => DS_STATUS_DOING,
        );
        $this->load->model('direct_seeding/Model_direct_seeding', 'ds');
        $ds_item = $this->ds->getOne($where);
        if (empty($ds_item))
        {
            return ;
        }


        $this->load->service('direct_seeding/service_direct_seeding_mixed_flow');
        $data = $this->service_direct_seeding_mixed_flow->index($ds_item['ds_id'], DIRECT_SEEDING_MIXED_FLOW_TYPE_CLOSED);
    }
}